package com.dataseek.iot.sys.manager.handler;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dataseek.iot.core.handler.ServiceHandler;
import com.dataseek.iot.core.response.ResponseEntity;
import com.dataseek.iot.mysql.entity.Province;
import com.dataseek.iot.mysql.entity.Province;
import com.dataseek.iot.mysql.service.impl.ProvinceServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @provinceor cc
 * @Title: 省份服务handler
 * @Description: 省份服务handler
 * @date 2021/10/267:11 下午
 * @since 1.0
 */
@Service
@Slf4j
public class ProvinceServiceHandler  extends ServiceHandler<Province> {

    @Autowired
    ProvinceServiceImpl provinceService;

    @Override
    public Mono<ResponseEntity> saveOne(Object entity) {
        Boolean b = provinceService.save((Province) entity);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> saveBatch(List lists) {
        Boolean b = provinceService.saveBatch(lists);
        return this.createResponse(b);
    }


    @Override
    public Mono<ResponseEntity> removeById(String id) {
        Boolean b = provinceService.removeById(id);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> removeAll(List ids) {
        Boolean b = provinceService.removeByIds(ids);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> updateOne(Object entity) {
        Boolean b = provinceService.updateById((Province) entity);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> updateBatch(List entities) {
        Boolean b =  provinceService.updateBatchById(entities);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> findOne(String id) {
        Province province = provinceService.getById(id);
        return this.createResponse(province);
    }

    public Mono<ResponseEntity> findOneByCode(String code){
        Province province = provinceService.getOneByCode(code);
        return this.createResponse(province);
    }


    @Override
    public Mono<ResponseEntity> page(Page p) {
        Page provincePage = provinceService.page(p);
        return this.createResponse(provincePage);
    }

    @Override
    public Mono<ResponseEntity> page(Page p, Wrapper wrapper) {
        Page provincePage = provinceService.page(p, wrapper);
        return this.createResponse(provincePage);
    }

    @Override
    public Flux<ResponseEntity> find(List ids) {
        List<Province> lists = provinceService.listByIds(ids);
        return this.createResponse(lists);
    }

    @Override
    public Flux<ResponseEntity> find(Wrapper wrapper) {
        List<Province> lists = provinceService.list(wrapper);
        return this.createResponse(lists);
    }

    @Override
    public Flux findAll() {
        List<Province> lists = provinceService.list();
        return this.createResponse(lists);
    }

    @Override
    public Mono<ResponseEntity> remove(Wrapper wrapper) {
        Boolean b = provinceService.remove(wrapper);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> remove(String id) {
        Boolean b = provinceService.removeById(id);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> update(Wrapper wrapper) {
        Boolean b = provinceService.update(wrapper);
        return this.createResponse(b);
    }


    @Override
    public Mono<ResponseEntity> defaultResponseOne(ResponseEntity responseEntity) {
        return Mono.just(responseEntity);
    }

    @Override
    public Flux<ResponseEntity> defaultResponseTwo(ResponseEntity responseEntity) {
        return Flux.just(responseEntity);
    }
    
    

}
